﻿<BadHabit_Factory_Controls:TaskViewerBase
    x:Name="taskViewer"
    x:Class="BadHabit.Factory.Controls.TaskDataGrid"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"    
    xmlns:BadHabit_Factory="clr-namespace:BadHabit.Factory"    
    xmlns:BadHabit_Factory_Converters="clr-namespace:BadHabit.Factory.Converters"  
    xmlns:Factory_Core="clr-namespace:BadHabit.Factory;assembly=FactoryCore"
    xmlns:BadHabit_WPFTools="clr-namespace:BadHabit.WPFTools;assembly=BadHabit.WPFTools"    
    xmlns:BadHabit_WPFTools_Converters="clr-namespace:BadHabit.WPFTools.Converters;assembly=BadHabit.WPFTools"
    
    xmlns:BadHabit_Factory_Controls="clr-namespace:BadHabit.Factory.Controls"  
    xmlns:Microsoft_Toolkit="http://schemas.microsoft.com/wpf/2008/toolkit"
    
    xmlns:props="clr-namespace:BadHabit.Factory.Properties"
    
    DataContextChanged="TaskViewerBase_DataContextChanged">
    <BadHabit_Factory_Controls:TaskViewerBase.Resources>        
        
     
        <BadHabit_Factory_Converters:TaskIdConverter x:Key="TaskIdConverter"/>
        <BadHabit_Factory_Converters:IsReadOnlyTaskConverter x:Key="IsReadOnlyTaskConverter"/>



        
        <DataTemplate x:Key="TaskTypeSelectedTemplate">
            <Image Style="{StaticResource TaskTypeImage}" Width="24" Height="24"/>
        </DataTemplate>
        

        <DataTemplate x:Key="TaskStatusSelectedTemplate">
            <Image Style="{StaticResource TaskStatusImage}"  Width="24" Height="24" Stretch="Uniform"/>
        </DataTemplate>


    </BadHabit_Factory_Controls:TaskViewerBase.Resources>
    
    <BadHabit_Factory_Controls:TaskViewerBase.CommandBindings>
        <CommandBinding Command="BadHabit_Factory:FactoryCommands.ViewTaskTail" Executed="ViewTaskTailCommandBinding_Executed" />        
        <CommandBinding Command="BadHabit_Factory:FactoryCommands.CancelTask" Executed="CancelTaskCommandBinding_Executed" />
        <CommandBinding Command="BadHabit_Factory:FactoryCommands.DoneTask" Executed="DoneTaskCommandBinding_Executed" />
        <CommandBinding Command="BadHabit_Factory:FactoryCommands.UnitChangeTask" Executed="UnitChangeTaskCommandBinding_Executed" />
        <CommandBinding Command="BadHabit_Factory:FactoryCommands.IsPayableChangeTask" Executed="IsPayableChangeTaskCommandBinding_Executed" />        
        <CommandBinding Command="BadHabit_Factory:FactoryCommands.MoveTask" Executed="MoveTaskCommandBinding_Executed" />
        <CommandBinding Command="BadHabit_Factory:FactoryCommands.AddTaskMaterial" Executed="AddTaskMaterial_Executed" />
        <CommandBinding Command="BadHabit_Factory:FactoryCommands.AddTaskMaterialLink" Executed="AddTaskMaterialLink_Executed" />
        <CommandBinding Command="BadHabit_Factory:FactoryCommands.OpenItemDetail" Executed="OpenItemDetail_Executed" />
    </BadHabit_Factory_Controls:TaskViewerBase.CommandBindings>



    <BadHabit_WPFTools:DataGrid
                x:Name="taskDataGrid"
                Grid.Column="1" Grid.Row="1"
                HorizontalAlignment="Stretch"
                VerticalAlignment="Stretch"
                ItemsSource="{Binding}"
                AutoGenerateColumns="False"
        
        
                UseNavigationExtensions="True"
                
                IsSynchronizedWithCurrentItem="True"
        
                AreRowDetailsFrozen="True"
        
                CurrentCellChanged="CurrentCellChanged"
                PreparingCellForEdit="taskDataGrid_PreparingCellForEdit"
        
                Margin="2,2,2,2"                
                GridLinesVisibility="Horizontal"
                HorizontalGridLinesBrush="{StaticResource WaterMarkBrush}"
                RowHeaderWidth="0"
                RowHeight="60"
                                
                BorderThickness="0,0,0,0"                                
                SelectionMode="Extended"
                SelectionUnit="FullRow"
        
                InitializingNewItem="taskDataGrid_InitializingNewItem"
        
                CanUserAddRows="False"
                CanUserDeleteRows="False"
        
                ScrollViewer.HorizontalScrollBarVisibility="Disabled"
                ScrollViewer.VerticalScrollBarVisibility="Auto">
                                      
        
        <Microsoft_Toolkit:DataGrid.CellStyle>
            <Style TargetType="Microsoft_Toolkit:DataGridCell" BasedOn="{StaticResource {x:Type Microsoft_Toolkit:DataGridCell}}">                
                <Setter Property="ContextMenu" Value="{StaticResource TaskContextMenu}"/>
            </Style>
        </Microsoft_Toolkit:DataGrid.CellStyle>
       

        <Microsoft_Toolkit:DataGrid.Columns>
            
       
            <Microsoft_Toolkit:DataGridTextColumn             
                        Header="#"
                        CanUserResize="False" CanUserReorder="False" CanUserSort="true"
                        Width="40"                          
                        Binding="{Binding TaskId, Converter={StaticResource TaskIdConverter}}"                 
                        IsReadOnly="True"/>


            <Microsoft_Toolkit:DataGridTemplateColumn                    
                        Header="{x:Static props:Resources.Status}"
                        CellStyle="{StaticResource CenterAlignCellStyle}"
                        CanUserResize="False" CanUserReorder="False" CanUserSort="False"                         
                        Width="40">
                <Microsoft_Toolkit:DataGridTemplateColumn.CellEditingTemplate>
                    <DataTemplate>
                        <BadHabit_WPFTools:ComboBox                               
                                        
                                        Style="{StaticResource ClickOnComboBox}"
                                        IsReadOnly="{Binding ., Converter={StaticResource IsReadOnlyTaskConverter}}"                                                                                                            
                                        HorizontalContentAlignment="Center" VerticalContentAlignment="Center"                                                                                                                        
                                        SelectedValue="{Binding Status, Converter={StaticResource EnumConverter}, ConverterParameter={x:Type Factory_Core:TaskStatus} }"   
                                        ItemsSource="{Binding Source={StaticResource TaskStatusList}}"
                                        ItemTemplate="{StaticResource TaskStatusTemplate}"
                                        SelectedItemTemplate="{StaticResource TaskStatusSelectedTemplate}"                                        
                                        />
                    </DataTemplate>
                </Microsoft_Toolkit:DataGridTemplateColumn.CellEditingTemplate>
                <Microsoft_Toolkit:DataGridTemplateColumn.CellTemplate>
                    <DataTemplate>
                        <Image Style="{StaticResource TaskStatusImage}"
                               
                               DataContext="{Binding Status, Converter={StaticResource EnumConverter}, ConverterParameter={x:Type Factory_Core:TaskStatus} }"
                               Width="24" Height="24" Stretch="Uniform"/>
                    </DataTemplate>
                </Microsoft_Toolkit:DataGridTemplateColumn.CellTemplate>
            </Microsoft_Toolkit:DataGridTemplateColumn>

            <Microsoft_Toolkit:DataGridTemplateColumn                    
                        CanUserResize="False" CanUserReorder="False" CanUserSort="False" 
                        CellStyle="{StaticResource CenterAlignCellStyle}"
                        Header="{x:Static props:Resources.Type}"
                        Width="40">
                <Microsoft_Toolkit:DataGridTemplateColumn.CellEditingTemplate>
                    <DataTemplate>
                        <BadHabit_WPFTools:ComboBox                                                                                                                                                    
                        
                                        IsReadOnly="{Binding ., Converter={StaticResource IsReadOnlyTaskConverter}}"                                                                          
                                        Style="{StaticResource ClickOnComboBox}"
                                        HorizontalContentAlignment="Center" VerticalContentAlignment="Center"                                                                                                                                                             
                                        SelectedValue="{Binding TaskType, Converter={StaticResource EnumConverter}, ConverterParameter={x:Type Factory_Core:TaskTypes} }"   
                                        ItemsSource="{Binding Source={StaticResource TaskTypeList}}"
                                        ItemTemplate="{StaticResource TaskTypeTemplate}"
                                        SelectedItemTemplate="{StaticResource TaskTypeSelectedTemplate}"/>
                    </DataTemplate>
                </Microsoft_Toolkit:DataGridTemplateColumn.CellEditingTemplate>
                <Microsoft_Toolkit:DataGridTemplateColumn.CellTemplate>
                    <DataTemplate>
                        <Image Style="{StaticResource TaskTypeImage}"
                        
                               DataContext="{Binding TaskType, Converter={StaticResource EnumConverter}, ConverterParameter={x:Type Factory_Core:TaskTypes} }"
                               Width="24" Height="24" Stretch="Uniform"/>
                    </DataTemplate>
                </Microsoft_Toolkit:DataGridTemplateColumn.CellTemplate>

            </Microsoft_Toolkit:DataGridTemplateColumn>


            <Microsoft_Toolkit:DataGridTextColumn
                CanUserResize="True" CanUserReorder="False" CanUserSort="true"
                Header="{x:Static props:Resources.Task}"
                Width="*"                                                   
                ElementStyle="{StaticResource NeedToSeeTextElementStyle}"
                Binding="{Binding TaskName}">                
                   
                <Microsoft_Toolkit:DataGridTextColumn.CellStyle>
                    <Style TargetType="Microsoft_Toolkit:DataGridCell" BasedOn="{StaticResource DetailCellStyle}">
                        <Setter Property="VerticalAlignment" Value="Stretch"/>                        
                        <Setter Property="VerticalContentAlignment" Value="Center"/>
                        <Setter Property="ContextMenu" Value="{StaticResource TaskContextMenu}"/>
                    </Style>
                </Microsoft_Toolkit:DataGridTextColumn.CellStyle>
                
                <Microsoft_Toolkit:DataGridTextColumn.EditingElementStyle>
                    <Style TargetType="TextBox" BasedOn="{StaticResource NeedToSeeTextEditingElementStyle}">
                        <Setter Property="MaxLength" Value="100"/>
                    </Style>
                </Microsoft_Toolkit:DataGridTextColumn.EditingElementStyle>


            </Microsoft_Toolkit:DataGridTextColumn>

            <Microsoft_Toolkit:DataGridTemplateColumn                            
                        CanUserResize="True" CanUserReorder="False" CanUserSort="true"
                        CellStyle="{StaticResource StretchAlignCellStyle}"
                        Header="{x:Static props:Resources.Assignee}"                
                        MinWidth="120">
                
                <Microsoft_Toolkit:DataGridTemplateColumn.CellTemplate>
                    <DataTemplate>
                        <BadHabit_WPFTools:ComboBox
                                Style="{StaticResource TeamComboBox}"                                
                                BadHabit_WPFTools:RoleChecker.RequiredEnableRole="SCRUM_MASTER"
                                ItemsSource="{Binding Source={StaticResource ProjectMemberList}}"                                
                                SelectionChanged="UpdateTaskUnitNameByMember"/>
                    </DataTemplate>            
                </Microsoft_Toolkit:DataGridTemplateColumn.CellTemplate>
                <Microsoft_Toolkit:DataGridTemplateColumn.CellEditingTemplate>
                    <DataTemplate>                                             
                        <BadHabit_WPFTools:ComboBox
                                
                                Style="{StaticResource TeamComboBox}"                                
                                BadHabit_WPFTools:RoleChecker.RequiredEnableRole="SCRUM_MASTER"
                                ItemsSource="{Binding Source={StaticResource ProjectMemberList}}"                                
                                SelectionChanged="UpdateTaskUnitNameByMember"/>
                    </DataTemplate>
                </Microsoft_Toolkit:DataGridTemplateColumn.CellEditingTemplate>


            </Microsoft_Toolkit:DataGridTemplateColumn>


            <Microsoft_Toolkit:DataGridTextColumn
                        CanUserResize="True" CanUserReorder="False" CanUserSort="true"
                        Header="{x:Static props:Resources.Plan}"                                           
                        Width="50"                        
                        CellStyle="{StaticResource RightAlignCellStyle}"                        
                        IsReadOnly="{Binding ., Converter={StaticResource IsReadOnlyTaskConverter}}"
                        Binding="{Binding PlannedEffort, StringFormat='{}{0:f1}', ValidatesOnExceptions=True, NotifyOnValidationError=True, ValidatesOnDataErrors=True}" 
                        >
                <Microsoft_Toolkit:DataGridTextColumn.EditingElementStyle>
                    <Style TargetType="TextBox"                           
                           BasedOn="{x:Static Microsoft_Toolkit:DataGridTextColumn.DefaultEditingElementStyle}">
                        <Setter Property="IsReadOnly" Value="{Binding ., Converter={StaticResource IsReadOnlyTaskConverter}}" />
                        <Setter Property="Background" Value="Transparent"/>
                    </Style>
                </Microsoft_Toolkit:DataGridTextColumn.EditingElementStyle>
            </Microsoft_Toolkit:DataGridTextColumn>
            <Microsoft_Toolkit:DataGridTextColumn
                        CanUserResize="True" CanUserReorder="False" CanUserSort="true"                        
                        Header="{x:Static props:Resources.Worked}"                                                  
                        Width="50"
                        CellStyle="{StaticResource RightAlignCellStyle}"
                
                        IsReadOnly="{Binding ., Converter={StaticResource IsReadOnlyTaskConverter}}"
                        Binding="{Binding ActualEffort, StringFormat='{}{0:f1}', ValidatesOnExceptions=True, NotifyOnValidationError=True, ValidatesOnDataErrors=True}" 
                        >
                <Microsoft_Toolkit:DataGridTextColumn.EditingElementStyle>
                    <Style TargetType="TextBox" BasedOn="{x:Static Microsoft_Toolkit:DataGridTextColumn.DefaultEditingElementStyle}">
                        <Setter Property="IsReadOnly" Value="{Binding ., Converter={StaticResource IsReadOnlyTaskConverter}}" />
                        <Setter Property="Background" Value="Transparent"/>
                    </Style>
                </Microsoft_Toolkit:DataGridTextColumn.EditingElementStyle>
            </Microsoft_Toolkit:DataGridTextColumn>

            <Microsoft_Toolkit:DataGridTemplateColumn
                    Header="{x:Static props:Resources.Pay}"                
                    CanUserResize="False"
                    
                    CellStyle="{StaticResource CenterAlignCellStyle}"                                        
                    Width="Auto">
                <Microsoft_Toolkit:DataGridTemplateColumn.CellTemplate>
                    <DataTemplate>
                        <CheckBox IsChecked="{Binding Payable}" >
                            <CheckBox.Style>
                                <Style TargetType="CheckBox" BasedOn="{StaticResource {x:Type CheckBox}}">
                                    <Style.Triggers>
                                        <DataTrigger Binding="{Binding ., Converter={StaticResource IsReadOnlyTaskConverter}}" Value="True">
                                            <Setter Property="CheckBox.IsEnabled" Value="False"/>
                                        </DataTrigger>
                                    </Style.Triggers>
                                </Style>
                            </CheckBox.Style>
                        </CheckBox>
                    </DataTemplate>
                </Microsoft_Toolkit:DataGridTemplateColumn.CellTemplate>
            </Microsoft_Toolkit:DataGridTemplateColumn>



        </Microsoft_Toolkit:DataGrid.Columns>
        
        
        
    </BadHabit_WPFTools:DataGrid>


</BadHabit_Factory_Controls:TaskViewerBase>
